import random

def generate_test_case(num_items=3, max_price=10, max_needs=5, max_specials=5):
    """生成购物优惠问题的测试用例
    
    Args:
        num_items: 物品种类数
        max_price: 单个物品的最大价格
        max_needs: 每种物品的最大需求量
        max_specials: 特价套餐的最大数量
    
    Returns:
        tuple: (price, special, needs)
    """
    # 生成每种物品的价格
    price = [random.randint(1, max_price) for _ in range(num_items)]
    
    # 生成需求
    needs = [random.randint(1, max_needs) for _ in range(num_items)]
    
    # 生成特价套餐
    special = []
    num_specials = random.randint(0, max_specials)
    
    for _ in range(num_specials):
        # 随机决定套餐中每种物品的数量（可能为0）
        items_in_special = [random.randint(0, max_needs // 2) for _ in range(num_items)]
        
        # 计算单独购买这些物品的总价
        total_alone = sum(items_in_special[i] * price[i] for i in range(num_items))
        
        # 套餐价格为单独购买总价的一定比例（0.5-0.9），或者是随机低价（确保有吸引力）
        if total_alone > 0:
            discount = random.uniform(0.5, 0.9)
            special_price = max(1, int(total_alone * discount))
        else:
            special_price = random.randint(1, max_price)
        
        special.append(items_in_special + [special_price])
    
    return price, special, needs

def generate_multiple_test_cases(n=5):
    """生成多个测试用例
    
    Args:
        n: 测试用例数量
    
    Returns:
        list: 包含n个测试用例的列表
    """
    test_cases = []
    for i in range(n):
        # 随机化参数以生成多样化的测试用例
        num_items = random.randint(2, 5)
        max_price = random.randint(5, 15)
        max_needs = random.randint(3, 8)
        max_specials = random.randint(3, 10)
        
        test_case = generate_test_case(num_items, max_price, max_needs, max_specials)
        test_cases.append(test_case)
    return test_cases

if __name__ == "__main__":
    # 生成一个测试用例并打印
    price, special, needs = generate_test_case()
    print("生成的测试用例:")
    print(f"价格: {price}")
    print(f"需求: {needs}")
    print("特价套餐:")
    for s in special:
        print(f"  {s[:-1]} -> 价格: {s[-1]}")    